Skip to content

M04 DHCP and Static Routing

Back to the Course Schedule

Lecture Videos

DHCP - Dynamic Host Configuration Protocol

Previous chapter discussed about addressing devices manually. This is laborous and ineffective way to work, but necessary in the end of 1990 when standard methods of distributing addresses weren't widely available (or supported).

Jumping to this day and age, DHCP has become such an standard component of every network, that you will come across it several times during your studies. Repetition is one step to mastery.

RFC 2131 - Dynamic Host Configuration Protocol

The Dynamic Host Configuration Protocol (DHCP) provides configuration parameters to Internet hosts. DHCP consists of two components:

  1. a protocol for delivering host-specific configuration parameters from a DHCP server to a host
  2. and a mechanism for allocation of network addresses to hosts.

In DHCP, there needs to be a server component in the network which distributes addresses to clients.

  • DHCP Server(s) can be
    • Linux Operating System (e.g. Centos 8)
    • Windows Operating System (e.g. Windows Server)
    • Router
      • e.g. Vyos we will use this on this course
      • Your home Router
  • DHCP Client(s) can be
    • Mobile Phones
    • Laptops
    • Personal Computers
    • IoT -devices
    • Fridges
    • Toasters
    • Cars
    • Robotic Vacuum Cleaners
    • ... anything that is connected to the Internet

So DHCP is everywhere.

DHCP is sometimes called DHCPv4 for IPv4 usage

IPv6 & DHCP

IPv6 planned to get rid of DHCP through EUI64 & SLAAC addressing formats.

DHCP still ensists of getting implemented through DHCPv6 (RFC 8415).

Messaging between the devices

DHCP uses UDP port 68 and UDP port 67 for transmission (formelly known as Bootstrap protocol). Figure below shows the basic communication between devices for automatic IP addressing.

!a

DHCPDISCOVER

Sent by the client to "discover" what DHCP servers are available in the network and what network parameters they have to offer.

Packet capture of DHCPDISCOVER

!a

DHCPOFFER

Sent by the server as a response to DHCPDISCOVER to the client. The server uses this message to suggest configuration parameters to the client.

Packet capture of DHCPOFFER

!a

DHCPREQUEST

Once the client receives an offer, it has to request a dhcp binding for those parameters. This recognizes that both parties have heard of each other and are willing to communicate for further for configuration.

Packet capture of DHCPREQUEST

!a

DHCPACK

The server confirms the settings and bindings by sending a DHCPACK. This confirms that both parties agree on the configuration parameters.

Packet capture of DHCPACK

!a

Making Vyos a DHCP Server

Our topology uses Vyos as an DHCP server. In configuration we can type the following commands:

set service dhcp-server shared-network-name VLAN5 subnet 192.168.0.0/24 default-router 192.168.0.254

Sets the default gateway parameters for subnet 192.168.0.0/24 to point towards 192.168.0.254

set service dhcp-server shared-network-name VLAN5 subnet 192.168.0.0/24 range PCs start 192.168.0.2

Starts to allocate/bind addresses from the address space. Beginning from the address 192.168.0.2.

set service dhcp-server shared-network-name VLAN5 subnet 192.168.0.0/24 range PCs stop 192.168.0.250

Stops to allocate/bind addresses from the address space. Ending in the address 192.168.0.250.

Would look like in show configuration

service {
    dhcp-server {
        shared-network-name VLAN5 {
            subnet 192.168.0.0/24 {
                default-router 192.168.0.254
                range PCs {
                    start 192.168.0.2
                    stop 192.168.0.250
                }
            }
        }
    }
}
Danger: If you have multiple subnets, use differed shared-network-name for them!

e.g.

```

service { dhcp-server { shared-network-name VLAN5 { subnet 192.168.0.0/24 { default-router 192.168.0.254 range PCs { start 192.168.0.2 stop 192.168.0.250 }

    shared-network-name VLAN10 {
        subnet 192.168.2.0/24 {
            default-router 192.168.2.254
            range PCs {
                start 192.168.2.2
                stop 192.168.2.250
            }
        }
    }
}

} ```

Once committed and end devices turned to automatic configuration, the server will show active leases distributed to end devices.

show dhcp server leases

vyos@vyos:~$ show dhcp server leases
IP address    Hardware address    Lease expiration     Pool    Client Name
------------  ------------------  -------------------  ------  ------------------
192.168.0.2   08:00:27:03:c2:9a   2020/08/06 08:01:49  VLAN5   lubuntu-VirtualBox
It is sometimes necessary to force the DHCP client to immediately ask for an IP address

ipconfig /release

ipconfig /renew

dhclient -r

or

ifdown eth0

ifup eth0

DHCP can sometimes remember a lot (read: be a pain) so often full reboots are necessary to get all the parameters wiped from the OS's memory.

Static Routing

Now we are moving out of the LAN's into Router to Router networks. Routers often work at intersections of subnets, thus they can be seen as traffic lights and traffic signs of those crossroads. They permit traffic through and choices of directions are made based on some metric (typically distance e.g. kilometers in traffic).

Static routes are decisions by network administrators on how to place the signs in those crossroads.

Example: Static route

set protocols static route <subnet> next-hop <how to get there / next-hop>

e.g.

set protocols static route 172.16.0.0/24 next-hop 25.0.0.2

This is similar to a crossroads signs

set a static sign <Helsinki> next-hop <turn left>

The example above works in the topology below. Ampere router is getting the set protocols static route 172.16.0.0/24 next-hop 25.0.0.2 -command, because it doesn't have any "lines" (actually ethernet adapters) to the IP subnet of 172.16.0.0/24. Ampere router doesn't know where that subnet is unless it is told so by a static route.

!a

Symmetric & Asymmetric routing

Almost always the telecommunications / network traffic between computers is bidirectional / two-way communications. Both parties want to send traffic to one another: client <-> server. This requires that routing should be complete in all the intersections/routers.

In the example earlier we only added a route from right to left, but there is no route back. This can be thought of going from Jyväskylä to Helsinki, but ... how do we get from Helsinki to Jyväskylä? Well... there are two options, through Lahti or Tampere!

!a

Of course you might take a different route back. And ... why?

!a

Well of course because Jyväskylä - Lahti - Helsinki is shorter, thus it will take less gas and cost less.

This same principle is at the heart of routing. There are reasons for a IPv4 packet to deviate from the shortest path, but typically and quite often... the shortest path is preferred.

Example - Symmetric

Given the example below

!a

To achieve Symmetric routing, the following commands are needed:

On the Ampere -router: set protocols static route 172.16.0.0/24 next-hop 25.0.0.2

and on the Candela -router: set protocols static route 192.168.0.0/24 next-hop 25.0.0.1

If both subnets are symmetrically routed, the Candela -router needs also: set protocols static route 192.168.10.0/24 next-hop 25.0.0.1

Example - Asymmetric

The same thing in asymmetric would mean changes to the routes (given in symmetric routing).

!a

On the Ampere -router: set protocols static route 172.16.0.0/24 next-hop 25.0.0.2

and on the Candela -router: `set protocols static route 192.168.0.0/24 next-hop 50.0.0.1

Route selection process

We use the topology below to illustrate the route selection process.

!a

Once the Ampere router receives the IP packet, it looks through the Destination Address -field of the packet. Given that the address would be 172.16.0.32 it can then start to look for the longest prefix match in the routing table.

Protocol IP Network Mask Interface
Connected 25.0.0.0 / 30 Ethernet 3
Connected 192.168.0.0 / 24 Ethernet 1
Connected 192.168.10.0 / 24 Ethernet 2
Static 172.16.0.0 / 24 Ethernet 3

For this every routes subnet mask is used to do the AND process (remember from subnetting?) to find out which route fits the best.

In this case if we take our previously installed static route into use 172.16.0.0/24 we can dissect the subnet mask /24 out of the route. We can then use it to calculate if the Destination Address fits the subnet mask by using the following calculation:

1010 1100 . 0001 0000. 0000 0000 . 0010 0000 the destination address in BIN format.

1111 1111 . 1111 1111. 1111 1111 . 0000 0000 the subnet mask in BIN format.

We use the AND truth gate to cycle through the bit pairs of both addresses to find out that 172.16.0.32 belongs in 172.16.0.0 subnet. And is the best match in the routing table.

Thus the packet is forwarded out of Ethernet 3 interface.

Warning: The example was a direct match with a small table... larger routing tables lead to more complicated situations

There are multiple different things to consider with conflicting routes.

Typically the basic is Administrative Distance and Metric(s). Althought Metric changes from dynamic routing protocol to another.

But these are for later courses.

Continue to the Exercises

E05 Configuring DHCP and Static Routing

Self-reflect the material with a small quiz?

Data Networks Quiz - M04 DHCP and Static Routing

Back to the Schedule?

Back to the Course Schedule


License

This course and its materials are written by Karo Saharinen and licenced by Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) license.

Creative Commons -licence